<?php

class Sistema_Form_Menu extends Zend_Form
{

    public function init()
    {
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;
        
        $this->setName('form_menu');
        
        $el = new Zend_Form_Element_Hidden('MEN_ID',array('disableLoadDefaultDecorators' =>true));
        $el->addDecorators(array(array('ViewHelper'),array('Errors')))
            ->addFilter('Int');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('MEN_NOME');
        $el->setLabel('Nome')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('MEN_ORD');
        $el->setLabel('Ordem')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Checkbox('MEN_STA',array('checked'=>'checked'));
        $el->setLabel('Ativo')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty');
        $this->addElement($el);
        
        /*
        $arr = array(
            'm_i_cadastro' => 'Cadastro',
            'm_i_configuracao' => 'Configuração',
            'm_i_configuracao2' => 'Configuração 2',
            'm_i_inc' => 'Incremento',
            'm_i_dec' => 'Decremento',
            'm_i_relatorio' => 'Relatório',
            'm_i_seguranca' => 'Segurança',
            'm_i_engenagem' => 'Engrenagem',
            'm_i_firewall'  => 'Firewall',
            'm_i_pasta'     => 'Pasta',
            'm_i_book'      => 'Livro',
        );
        asort($arr);
        $el=new Zend_Form_Element_Select('MEN_CSS',array('onchange' => ''));
        $el->setLabel('Estilo')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty')
        ->addMultiOptions($arr);
        $this->addElement($el);
         
        $img = 'public/upload/'.$controller.'/'.$front->getRequest()->getParam('id').'.*';
        foreach (glob($img) as $src) {
            $el = new Zend_Form_Element('img',array( 'helper'=>'formNote', 'value'=>'<img src="'.$front->getBaseUrl().'/'.$src.'" />' ));
            $this->addElement($el);
        }
        
        $el = new Zend_Form_Element_File('MEN_FILE');
        $el->setLabel('Imagem - Tamanho: 27x20')
	->addValidator('Extension', false, array('jpg', 'png', 'gif'));
        $this->addElement($el);
        */
        
        $btn = new Zend_Form_Element_Submit('Salvar',array('disableLoadDefaultDecorators' =>true));
        $btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setAttrib('id', 'submitbutton');
        $btn->setAttrib('class', 'btn-frm');
        $btn->setLabel('Salvar');
        $this->addElement($btn);
        
        $btn = new Zend_Form_Element_Button('Cancelar',array('disableLoadDefaultDecorators' =>true));
        //$btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="'.$url.'" class="btn-frm">Voltar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);
        
    }

}

